﻿using B.Z.BasicData.API.Write.Application.Role;
using B.Z.BasicData.API.Write.Application.User;
using B.Z.BasicData.ErrorCode;
using MediatR;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;

namespace B.Z.BasicData.API.Write.Controllers
{
    /// <summary>
    /// 控制器-写（角色-用户）
    /// </summary>
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]
    public class ManageController : ControllerBase
    {
        private readonly IMediator mediator;

        public ManageController(IMediator mediator)
        {
            this.mediator = mediator;
        }
        /// <summary>
        /// 添加用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddUser(UserAddCommand command) 
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 修改用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> UpdateUser(UserUpdateCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 删除用户
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> RemoveUser(UserRemoveCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 添加角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddRole(RoleAddCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 删除/修改角色
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> EaditRole(RoleUpdateCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 分配员工
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> AddUserRole(UserRoleAddCommand command)
        {
            return mediator.Send(command);
        }
        /// <summary>
        /// 删除员工角色之间的关系
        /// </summary>
        /// <param name="command"></param>
        /// <returns></returns>
        [HttpPost]
        public Task<APIResult<int>> RemoveUserRole(UserRoleRemoveCommand command)
        {
            return mediator.Send(command);
        }
    }
}
